package chapter06;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Test15_PlayCards {
    public static void main(String[] args) {
        //模拟斗地主的发牌
        String[] flowers = {"♠","♥","♣","♦"};
        String[] numbers = {"A","2","3","4","5","6","7",
                "8","9","10","J","Q","K"};
        ArrayList<String> cards = new ArrayList<>();
        //将flowers中的所有元素和numbers中一一组合
        for (int i=0;i<flowers.length;i++){
            for(int j=0;j<numbers.length;j++){
                String a = flowers[i]+numbers[j];
                cards.add(a);
            }
        }
        cards.add("大王");
        cards.add("小王");
        System.out.println(cards);
        //洗牌
        Collections.shuffle(cards);
        System.out.println(cards);
        //发牌 subList 左闭右开[0,17)
        List<String> n1 = cards.subList(0, 17);
        System.out.println(n1);
        List<String> n2 = cards.subList(17, 34);
        System.out.println(n2);
        List<String> n3 = cards.subList(34, 51);
        System.out.println(n3);
        List<String> n4 = cards.subList(51, 54);
        System.out.println(n4);
        Collections.sort(n1, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                //数字一样的放一起
                return Character.compare(o1.toCharArray()[1],o2.toCharArray()[1]);
            }
        });
        System.out.println(n1);
    }
}
